define(
		[ 'require', 'echarts', 'echarts/chart/line', 'zrender/tool/util' ],
		function(require) {
			"use strict";

			var echarts = require('echarts');
			var zrUtil = require('zrender/tool/util');

			var forEach = Ember.EnumerableUtils.forEach;

			var defaultOption = {
				title : {
					text : '192.168.18.104',
					x : 'center'
				},
				tooltip : {
					trigger : 'item',
					showDelay: 0,
					formatter : "{a}<br/>{b}:{c}G({d}%)"
				},
				calculable : false,
				series : [ {
					name : '磁盘使用情况统计',
					type : 'pie',
					radius : '55%',
					center : [ '50%', '60%' ],
					itemStyle: {
							    normal: {
							        label: {
							            show: true,
							            position: 'outer',
							            formatter: "{b}:{c}G({d}%)"
							        },
							        labelLine: {
							            show: true,
							            length:-1
							        }
							    }
							},
					data : [ {
						value : 335,
						name : '性能数据'
					}, {
						value : 310,
						name : '系统数据'
					}, {
						value : 310,
						name : '剩余量'
					}]
				} ]
			};

			var DiskDataBarView = Ember.Component.extend({

						didInsertElement : function() {
							var $dom = this.$();

							this.width = this.width || $dom.width();
							this.height = this.height || $dom.height();

							if (this.width === 0 || this.height === 0) {
								Ember.assert("必须指定视图的width和height。（可通过样式或width，height属性");
								return;
							}

							this._initNormalChart();
						},

						/**
						 * 初始化概览图表
						 */
						_initNormalChart : function() {
							var $dom = this.$();

							if (G_vmlCanvasManager && G_vmlCanvasManager.init) {
								G_vmlCanvasManager.initElement($dom[0]);
							}

							var overviewChart = echarts.init($dom[0]);
//							overviewChart.setOption(defaultOption);
							this.overviewChart = overviewChart;
							this.detailDataChange();
						},

						/**
						 * 数据改变后, 根据显示模式设置为相应的数据
						 */
						dataChange : Ember.observer("data", function() {
							this.detailDataChange();
						}),

						/**
						 * 详细数据改变后, 刷新概览图表
						 */
						detailDataChange : function() {
							if (!this.overviewChart) {
								return;
							}

							var option = zrUtil.clone(defaultOption);

							var data = this.get("data") || [];
							if (data) {
								option.title.text = data.name || {};
								if (!data.name) {
									option.title.text = "-";
								};
								var seriesData = option.series[0].data = [];
								this._translateDataToOption(data,seriesData);
								this.overviewChart.setOption(option, true);
								this.overviewChart.hideLoading();
							}
						},

						/**
						 * 将原始值转换为柱形图需要的series配置
						 */
						_translateSeriesDataItem : function(DataVal) {
							var value = DataVal.value, 
							valueItem = {
								value : value === undefined ? "-" : value,
								name : DataVal.name
							};
							return valueItem;
						},

						/**
						 * 将原始值转换为柱形图的配置
						 */
						_translateDataToOption : function(data,seriesData) {
							var view = this;

							// 磁盘使用情况数组
							var diskDatas = [];
								var diskFree={};
								diskFree.name="剩余量";
								diskFree.value=data.freeData;
								var diskother={};
								diskother.name="系统数据";
								diskother.value=data.otherData;
								var diskUse={};
								diskUse.name="性能数据";
								diskUse.value=data.useData;
								diskDatas.push(diskUse);
								diskDatas.push(diskFree);
							// 磁盘使用情况
							forEach(diskDatas, function(diskData) {
								var valueItem = view._translateSeriesDataItem(diskData);
								seriesData.push(valueItem);
							});
						}
					});

			APM.ui.DiskDataBar = DiskDataBarView;

			return DiskDataBarView;
		});